#include <bits/stdc++.h>

using namespace std;
const int maxn = 13 + 2;
int N;
bool vis[3][maxn * 2];
int cnt = 0;
int C[maxn];

void search(int r) {
    if (r > N) {
        if (cnt < 3) {
            for (int i = 1; i <= N; ++i) {
                if (i!=1) cout << " ";
                cout << C[i];
            }
            cout << '\n';
        }
        ++cnt;
    } else {
        for (int c = 1; c <= N; ++c) {
            if (!vis[0][c] && !vis[1][c - r + N] && !vis[2][c + r]) {
                vis[0][c] = vis[1][c - r + N] = vis[2][c + r] = true;
                if(cnt < 3) C[r] = c;
                search(r + 1);
                vis[0][c] = vis[1][c - r + N] = vis[2][c + r] = false;
            }
        }
    }

}

void init() {
    memset(vis, false, sizeof(vis));
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    init();
    search(1);
    cout << cnt << '\n';
    return 0;
}